home *** CD-ROM | disk | FTP | other *** search
- Path: news.princeton.edu!blume
- From: blume@zayin.cs.princeton.edu (Matthias Blume)
- Newsgroups: comp.lang.c++,comp.lang.c
- Subject: Re: Performance: C vs. C++
- Date: 27 Jan 1996 20:26:10 GMT
- Organization: Princeton University
- Distribution: world
- Message-ID: <BLUME.96Jan27152610@zayin.cs.princeton.edu>
- References: <30F6BAAC.12B5@iastate.edu> <4da9pn$a45@news.bridge.net>
- <4dnpl2$c8g@classic.iinet.com.au> <3105E9DC.1BE3@enermet.fi>
- <DLr46y.7rH@txnews.amd.com>
- NNTP-Posting-Host: zayin.cs.princeton.edu
- In-reply-to: Bret Patterson's message of Thu, 25 Jan 1996 19:16:09 GMT
-
- In article <DLr46y.7rH@txnews.amd.com> Bret Patterson <faustus> writes:
-
- Here is an example to illustrate why virtual functions do not cause extra overhead.
-
- C program:
-
- switch (object->type)
- {
- case 1 : DragonAttack();
- case 2 : OrcAttack();
- ...
- };
-
- and a C++:
- object->Attack(); // which internally g++ does a object->virtualTable[Function#]();
-
- Big deal. So c++ does a virtual table lookup, but in order for C to have this ability
- it has to use a switch statement or ifelse construct.
-
- Why? You just gave the _real_ C equivalent yourself! A
- multi-branch switch was never the C way of doing virtual functions.
- C++'s virtual functions are nothing more than glorified C function
- pointers.
-
- --
- -Matthias
-